package com.leyou.item.mapper;

import com.leyou.item.interfaces.pojo.Goods;
import com.leyou.item.interfaces.pojo.vo.GoodsPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;

/**
 * @Author yong.Mr
 * @data 2019-8-9
 * @version 1.0.0
 */
public interface GoodsMapper extends Mapper<Goods> {

    // 分页查询和模糊查询----->带分页的数据
    // #{saleable}参数上记得使用@Param("saleable")标记, 否则参数会找不到
    @Select("SELECT s.id,s.title,s.sub_title as subTitle,s.valid,b.name,s.brand_id as brandId,s.cid1,s.cid2,s.cid3,s.saleable FROM tb_spu s INNER JOIN tb_brand b ON s.brand_id = b.id"
            + " WHERE s.saleable = ${saleable} AND s.valid = 1 AND (s.title LIKE '%${key}%' OR b.name LIKE '%${key}%') limit ${(page-1)*rows},${rows}")
    List<GoodsPage> queryGoodsByPageSql(@Param("key") String key, @Param("saleable") Boolean saleable,
                                        @Param("page") Integer page,@Param("rows") Integer rows);

    // 查询模糊查询的所有数据
    @Select("SELECT s.id,s.title,b.name,s.cid1,s.cid2,s.cid3,s.saleable FROM tb_spu s INNER JOIN tb_brand b ON s.brand_id = b.id"
            + " WHERE s.saleable = ${saleable} AND s.valid = 1 AND (s.title LIKE '%${key}%' OR b.name LIKE '%${key}%')")
    List<GoodsPage> queryGoodsByPageAll(@Param("key")String key, @Param("saleable")Boolean saleable);
}
